import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';

/*
  Generated class for the Searchbar page.

  See http://ionicframework.com/docs/v2/components/#navigation for more info on
  Ionic pages and navigation.
*/
@Component({
  selector: 'page-searchbar',
  templateUrl: 'searchbar.html'
})
export class Searchbar {

  constructor(public navCtrl: NavController) {}

  ionViewDidLoad() {
    console.log('Hello Searchbar Page');
  }

items: Array<string>;

  ngOnInit() {
    this.setItems();
  }

  setItems() {
    this.items = ['Orange', 'Banana', 'Pear', 'Tomato', 'Grape', 'Apple', 'Cherries', 'Cranberries', 'Raspberries', 'Strawberries', 'Watermelon'];
  }

  filterItems(ev) {
    this.setItems();
    let val = ev.target.value;

    if (val && val.trim() !== '') {
      this.items = this.items.filter(function(item) {
        return item.toLowerCase().includes(val.toLowerCase());
      });
    }
  }
}
